package tencent

//快慢指针， 快慢指针的初始化条件。
func detectCycle(head *ListNode) *ListNode {
	s, f := head, head
	for f != nil && f.Next != nil {
		s = s.Next
		f = f.Next.Next
		if f == s {
			f = head
			for ; f != nil && s != f; s, f = s.Next, f.Next {
			}
			return f
		}
	}
	return nil
}
